package domain;

import java.util.ArrayList;

public class Prediction {
	private ArrayList<Similarity> similarityList;
	private double result1 = 0;
	private double result2 = 0;
	private double result3 = 0;
	
	public Prediction(User user1, ArrayList<User> otherUsers){
		this.similarityList = new ArrayList<Similarity>();
		for (int i = 0; i < otherUsers.size(); i++) {
			similarityList.add(new Similarity(user1, otherUsers.get(i)));
			similarityList.get(i).calculateSimilarity();
		}
	}
	
	public double calculatePrediction(){
		
		result1 = similarityList.get(0).getAverageUser1();
		
		for (int i = 0; i < similarityList.size(); i++) {
			result2 = result2 + (similarityList.get(i).getSim() * 
					(similarityList.get(i).getUser2().getPreference().getRatingList().get(4).getRate() - 
							similarityList.get(i).getAverageUser2()));
			result3 = result3 + similarityList.get(i).getSim();
		}
		
		return result1 + (result2/result3);
	}

	public boolean isRecommend()
	{
		
		if(this.calculatePrediction()>=2.5)
		{
			return true;
		}
		return false;
	}

	

}
